const api_url ="https://douban.uieee.com/v2/movie/subject/"
const api_urlc = "https://douban.uieee.com/v2/movie/subject/"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    movie:"",
    comment:[],
    id:0,
    pageSize: 20,
    pageIndex: 1,
    isShowComment:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (params) {
    this.setData({
      id: params.id,
    });
    wx.showLoading({
      title: '玩命加载中',
    });
    wx.request({
      url: api_url + params.id,
      data: {

      },
      method: "GET",
      header: {
        'content-type': 'application/json',
        'Content-Type': "json"
      },
      success: (res) => {
        this.setData({
          movie:res.data
        });
        wx.hideLoading(); 
      }
    })
  },
  //获取评论
  strtimeForamt: function (date){
    var dateformt = require('../../utils/common.js');
    var strdate = dateformt.getDateDiff(date);
    console.log(strdate);
    console.log(date);
    return strdate;
  },
  handelComment:function(){
    // 显示加载图标  
    wx.showLoading({
      title: '玩命加载中',
    });
    wx.request({
      url: api_urlc + this.data.id +"/comments",
      data: {
      },
      method: "GET",
      header: {
        'content-type': 'application/json',
        'Content-Type': "json"
      },
      success: (res) => {
        this.setData({
          comment: res.data.comments,
          isShowComment:true
        });
        wx.hideLoading();
      }
    })
  },
  //上拉加载更多
  onReachBottom: function () {
    if (!this.data.isShowComment){
        return false;
    }
    // 显示加载图标  
    wx.showLoading({
      title: '玩命加载中',
    });
    wx.request({
      url: api_urlc + this.data.id + "/comments",
      data: {
        start: this.data.pageIndex * this.data.pageSize
      },
      method: "GET",
      header: {
        'content-type': 'application/json',
        'Content-Type': "json"
      },
      success: (res) => {
        this.setData({
          comment: this.data.comment.concat(res.data.comments),
          pageIndex: this.data.pageIndex + 1
        });
        wx.hideLoading();
      }
    })
  },
})